﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Needs.ascx.cs" Inherits="controls_admin_Needs" %>
<script src="../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script src="../Scripts/jquery.tablednd_0_5.js" type="text/javascript"></script>
<script type="text/javascript">
    var variable = "0";
    var j = jQuery.noConflict();
    j(document).ready(function () {
        j('#table-3').tableDnD({
            onDrop: function (table, row) {
                //alert("/articles/ajaxTest.php?" + j.tableDnD.serialize());
                //alert("Result of j.tableDnD.serialise() is "+j.tableDnD.serialize());
                //j('#AjaxResult').load("/articles/ajaxTest.php?"+j.tableDnD.serialize());
                variable = j.tableDnD.serialize();
            }
        });
        j("#update").click(function () {
            j.ajax({
                type: "POST",
                url: "../services/Order.asmx/Need",
                data: "{'id':'&" + variable + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                beforeSend: function () {
                    j("#ctl00_divMessage").html("");
                },
                success: function (message) {
                    if (message.d == false) {
                        // Ẩn Nút Submit nếu UserName không hợp lệ
                        //alert("error");
                        j("#ctl00_divMessage").html("<div id='message-error' class='message message-error'><div class='image'><img src='../resources/images/icons/error.png' alt='Error' height='32' /></div><div class='text'><h6>Lỗi</h6><span>Chưa thực hiện được!</span></div><div class='dismiss'><a href='#message-error'></a></div></div>");
                    }
                    else {
                        //alert("ok");
                        j("#ctl00_divMessage").html("<div id='message-success' class='message message-success'><div class='image'><img src='../resources/images/icons/success.png' alt='Success' height='32' /></div><div class='text'><h6>Thông Báo</h6><span>Cập nhật thành công !</span></div><div class='dismiss'><a href='#message-success'></a></div></div>");
                    }
                },
                error: function (errormessage) {
                    //Hiển thị lỗi nếu xảy ra
                    //alert(errormessage);
                    j("#ctl00_divMessage").html("<div id='message-error' class='message message-error'><div class='image'><img src='../resources/images/icons/error.png' alt='Error' height='32' /></div><div class='text'><h6>Lỗi</h6><span>Chưa thực hiện được!</span></div><div class='dismiss'><a href='#message-error'></a></div></div>");
                }
            });
        });
    });   
</script>
<!-- table -->
<div class="box">
    <!-- box / title -->
    <div class="title">
        <h5>
            Nhu cầu</h5>
        <div class="search">
            <div class="input">
            </div>
            <div class="button">
            </div>
        </div>
    </div>
    <div id="divMessage" runat="server">
    </div>
    <div class="first-action">
        <asp:DropDownList ID="ddlCategories" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlCategories_SelectedIndexChanged"
            CssClass="select" />
    </div>
    <!-- end box / title -->
    <div class="table">
        <table id="table-3">
            <thead>
                <tr>
                    <th>
                        Nhu cầu
                    </th>
                    <th>
                        Sửa
                    </th>
                    <th class="last">
                        Xóa
                    </th>
                </tr>
            </thead>
            <tbody>
                <asp:Repeater ID="rptNeeds" runat="server" OnItemCommand="rptNeeds_ItemCommand">
                    <ItemTemplate>
                        <tr id="<%#Eval("NEED_ID") %>" style="cursor: move">
                            <td align="center">
                                <%#Eval("NEED_NAME")%>
                            </td>
                            <td align="center">
                                <a href='<%#"default.aspx?module=neededit&n_id="+Eval("NEED_ID") %>' title="Sửa">
                                    <img src="../Resources/icons/16x16/edit.png" alt='Sửa' class="icon-32-edit" />
                                </a>
                            </td>
                            <td class="last" align="center">
                                <asp:Button runat="server" ID="btnDel" CssClass="icon-32-delete" CommandName="del"
                                    CommandArgument='<%#Eval("NEED_ID")%>' BackColor="Transparent" BorderStyle="None"
                                    OnClientClick="return confirm('Bạn có chắc chắn muốn xóa không ?');" />
                            </td>
                        </tr>
                    </ItemTemplate>
                </asp:Repeater>
            </tbody>
        </table>
        <div class="action">
            <div class="button">
                <%--<asp:Button ID="btnStatus" runat="server" Text="Cập Nhật Thay Đổi" />--%>
                <asp:Button ID="btnAdd" runat="server" Text="Thêm Mới" OnClick="btnAdd_Click" />
                <input type="button" value="Cập nhật thứ tự" id="update" />
            </div>
        </div>
        <div style="text-align: center; margin: 10px">
            <%if (Session["url"] != null)
              {
                  if (Request.UrlReferrer != null)
                  {
                      if (!Request.UrlReferrer.ToString().Equals(Request.Url.ToString()))
                      {
                          Session["url"] = Request.UrlReferrer.ToString();                      
                  
            %>
            <a onclick="history.go(-1);" title="Trang trước">
                <%
}
                      else
                      {
                %>
                <a href='<%=Session["url"].ToString() %>' title="Trang trước">
                    <%   
}
                  }
                  else
                  {                      
                    %>
                    <a onclick="history.go(-1);" title="Trang trước">
                        <%}
              }
              else
              {
                  if (Request.UrlReferrer != null)
                      Session.Add("url", Request.UrlReferrer.ToString());
                  else
                      Session.Add("url", Request.Url.ToString());
                        %>
                        <a href="default.aspx" title="Trang trước">
                            <%} %>
                            <img src="../resources/images/icons/16x16/arrow-return.png" alt="Trang trước" /></a>
                        &nbsp;&nbsp; <a href="default.aspx" title="Trang chủ">
                            <img src="../resources/images/icons/16x16/home.png" alt="Trang chủ" /></a>
        </div>
    </div>
</div>
